package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtUserPromotionCodeRel;
import com.ruoyi.business.service.IJtUserPromotionCodeRelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 推广码绑定关系Controller
 * 
 * @author Alan Zhang
 * @date 2025-03-29
 */
@Controller
@RequestMapping("/business/promotion")
public class JtUserPromotionCodeRelController extends BaseController
{
    private String prefix = "business/promotion";

    @Autowired
    private IJtUserPromotionCodeRelService jtUserPromotionCodeRelService;

    @RequiresPermissions("business:promotion:view")
    @GetMapping()
    public String promotion()
    {
        return prefix + "/promotion";
    }

    /**
     * 查询推广码绑定关系列表
     */
    @RequiresPermissions("business:promotion:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtUserPromotionCodeRel jtUserPromotionCodeRel)
    {
        startPage();
        List<JtUserPromotionCodeRel> list = jtUserPromotionCodeRelService.selectJtUserPromotionCodeRelList(jtUserPromotionCodeRel);
        return getDataTable(list);
    }

    /**
     * 导出推广码绑定关系列表
     */
    @RequiresPermissions("business:promotion:export")
    @Log(title = "推广码绑定关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtUserPromotionCodeRel jtUserPromotionCodeRel)
    {
        List<JtUserPromotionCodeRel> list = jtUserPromotionCodeRelService.selectJtUserPromotionCodeRelList(jtUserPromotionCodeRel);
        ExcelUtil<JtUserPromotionCodeRel> util = new ExcelUtil<JtUserPromotionCodeRel>(JtUserPromotionCodeRel.class);
        return util.exportExcel(list, "推广码绑定关系数据");
    }

    /**
     * 新增推广码绑定关系
     */
    @RequiresPermissions("business:promotion:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存推广码绑定关系
     */
    @RequiresPermissions("business:promotion:add")
    @Log(title = "推广码绑定关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtUserPromotionCodeRel jtUserPromotionCodeRel)
    {
        return toAjax(jtUserPromotionCodeRelService.insertJtUserPromotionCodeRel(jtUserPromotionCodeRel));
    }

    /**
     * 修改推广码绑定关系
     */
    @RequiresPermissions("business:promotion:edit")
    @GetMapping("/edit/{relId}")
    public String edit(@PathVariable("relId") Long relId, ModelMap mmap)
    {
        JtUserPromotionCodeRel jtUserPromotionCodeRel = jtUserPromotionCodeRelService.selectJtUserPromotionCodeRelByRelId(relId);
        mmap.put("jtUserPromotionCodeRel", jtUserPromotionCodeRel);
        return prefix + "/edit";
    }

    /**
     * 修改保存推广码绑定关系
     */
    @RequiresPermissions("business:promotion:edit")
    @Log(title = "推广码绑定关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtUserPromotionCodeRel jtUserPromotionCodeRel)
    {
        return toAjax(jtUserPromotionCodeRelService.updateJtUserPromotionCodeRel(jtUserPromotionCodeRel));
    }

    /**
     * 删除推广码绑定关系
     */
    @RequiresPermissions("business:promotion:remove")
    @Log(title = "推广码绑定关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtUserPromotionCodeRelService.deleteJtUserPromotionCodeRelByRelIds(ids));
    }
}
